// 要能判断自己是否已经被实例化过，并且只实例化一次，需要用到单例模式。
// class SingleDog {
//     static getInstance() {
//         //1、 return new SingleDog();
//         // 2、SingleDog.instance = new SingleDog();
//         // return SingleDog.instance;
//         if (SingleDog.instance) {
//             return SingleDog.instance;
//         }
//         SingleDog.instance = new SingleDog();
//         return SingleDog.instance;
//     }
// }
// const s1 = SingleDog.getInstance();
// const s2 = SingleDog.getInstance();
// console.log(s1 === s2);

class SingleDog {
}
SingleDog.getInstance = (function () {
    let instance = null;
    return function () {
        if (!instance) {
            return instance = new SingleDog();
        }
        return instance;
    }
})()
// const s1 = SingleDog.getInstance();
// const s2 = SingleDog.getInstance();
// console.log(s1 === s2);//false
